﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ASCalpuff.FileLayers
{
    public class PG6:Group
    {
        /// <summary>
        /// 次网格尺度上地形特征的数量
        /// </summary>
        private int m_NHILL = 0;
        public int NHILL
        {
            get { return m_NHILL; }
            set { m_NHILL = value; }
        }


        /// <summary>
        /// 特殊次网格尺度上复杂地形受体点的数量
        /// </summary>
        private int m_NCTREC = 0;
        public int NCTREC
        {
            get { return m_NCTREC; }
            set { m_NCTREC = value; }
        }
        //是否以CTDM格式输入CTSGHILL的地形和受体点数据
        //1=用CTDM处理器创建数据并从HILL.DAT和HILLRCT.DAT文件中读取
        //2=用OPTHILL及以下自足的输入创建HILL数据
        private int m_MHILL = 2;
        public int MHILL
        {
            get { return m_MHILL; }
            set { m_MHILL = value; }
        }


        /// <summary>
        ///把水平面积转换为米的因子（只在 MHILL=1使用）
        /// </summary>
        private double m_XHILL2M = 1;
        public double XHILL2M
        {
            get { return m_XHILL2M; }
            set { m_XHILL2M = value; }
        }
        /// <summary>
        /// 转变垂向散布到米的因子（只在 MHILL=1使用）
        /// </summary>
        private double m_ZHILL2M = 1;
        public double ZHILL2M
        {
            get { return m_ZHILL2M; }
            set { m_ZHILL2M = value; }
        }

        /// <summary>
        /// CTDM坐标原点在calpuff坐标系统下的x坐标，对于calpuff来讲,单位千米
        /// </summary>
        private double m_XCTDMKM = 0;
        public double XCTDMKM
        {
            get { return m_XCTDMKM; }
            set { m_XCTDMKM = value; }
        }




        /// <summary>
        /// CTDM坐标原点在calpuff坐标系统下的Y坐标，对于calpuff来讲,单位千米
        /// </summary>
        private double m_YCTDMKM = 0;
        public double YCTDMKM
        {
            get { return m_YCTDMKM; }
            set { m_YCTDMKM = value; }
        }
        /// <summary>
        /// group 6b,HIll信息
        /// 每个hill被认为是一个单独的子组，在结尾必要有对界定符“！END！”
        /// </summary>
        private List<HillInformation> m_HillInfo = new List<HillInformation>();
        public List<HillInformation> HillInfo
        {
            get { return m_HillInfo; }
            set { m_HillInfo = value; }
        }
        /// <summary>
        /// group 6c,CTSG受体信息
        /// 每个hill被认为是一个单独的子组，在结尾必要有对界定符“！END！”
        /// </summary>
        private List<CTReceptorInfo> m_RecepInfo = new List<CTReceptorInfo>();
        public List<CTReceptorInfo> RecepInfo
        {
            get { return m_RecepInfo; }
            set { m_RecepInfo = value; }
        }

    

        public override void ReadFromGroup(Dictionary<string, string> dic)
        {
            foreach (KeyValuePair<string, string> m_dic in dic)
            {
                if (m_dic.Key == "NHILL")
                {
                    this.NHILL = Convert.ToInt32(m_dic.Value);
                }
                if (m_dic.Key == "NCTREC")
                {
                    this.NCTREC = Convert.ToInt32(m_dic.Value);
                }
                if (m_dic.Key == "MHILL")
                {
                    this.MHILL = Convert.ToInt32(m_dic.Value);
                }
                if (m_dic.Key == "XHILL2M")
                {
                    this.XHILL2M = Convert.ToDouble(m_dic.Value);
                }
                if (m_dic.Key == "ZHILL2M")
                {
                    this.ZHILL2M = Convert.ToDouble(m_dic.Value);
                }
                if (m_dic.Key == "XCTDMKM")
                {
                    this.XCTDMKM = Convert.ToDouble(m_dic.Value);
                }
                if (m_dic.Key == "YCTDMKM")
                {
                    this.YCTDMKM = Convert.ToDouble(m_dic.Value);
                }



                if (m_dic.Key == "HILL")
                {
                    HillInformation h = new HillInformation();

                    this.HillInfo.Add(h.ReadFromGroup(m_dic.Value));

                }

                if (m_dic.Key == "CTREC")
                {
                    CTReceptorInfo c = new CTReceptorInfo();


                    this.RecepInfo.Add(c.ReadFromGroup(m_dic.Value));

                }


            }

        }

        public override string WriteToGroup()
        {
            string ResultStr = "", TempStr;

            TempStr = StrWriter.GetCLine();
            TempStr += "INPUT GROUP: 6a, 6b, & 6c -- Subgrid scale complex terrain inputs" + "\r\n";
            ResultStr += TempStr;

            TempStr = StrWriter.GetCLine();
            ResultStr += TempStr;

            TempStr = "! NHILL = " + NHILL.ToString() + " !" + "\r\n";
            ResultStr += TempStr;

            TempStr = "! NCTREC = " + NCTREC.ToString() + " !" + "\r\n";
            ResultStr += TempStr;

            TempStr = "! MHILL = " + MHILL.ToString() + " !" + "\r\n";
            ResultStr += TempStr;

            TempStr = "! XHILL2M = " + XHILL2M.ToString() + " !" + "\r\n";
            ResultStr += TempStr;

            TempStr = "! ZHILL2M = " + ZHILL2M.ToString() + " !" + "\r\n";
            ResultStr += TempStr;

            TempStr = "! XCTDMKM = " + XCTDMKM.ToString() + " !" + "\r\n";
            ResultStr += TempStr;

            TempStr = "! YCTDMKM = " + YCTDMKM.ToString() + " !" + "\r\n";
            ResultStr += TempStr;
            ResultStr += "! END !" + "\r\n";
            //是否考虑地形影响 
            if (this.MHILL == 2)
            {
                int c = -1;
                for (int i = 0; i < this.HillInfo.Count; i++)
                {
                    c = i + 1;
                    TempStr = c + " !HILL =      " + Math.Round(HillInfo[i].XC, 5).ToString() + ",   " + Math.Round(HillInfo[i].YC, 5).ToString() + ",   " + HillInfo[i].THETAH.ToString() + ",   " + Math.Round(HillInfo[i].ZGRID, 3).ToString() + ",   " + Math.Round(HillInfo[i].RELIEF, 3).ToString() + ",   " + Math.Round(HillInfo[i].EXPO1, 3).ToString() + ",   " + Math.Round(HillInfo[i].EXPO2, 3).ToString() + ",   " + Math.Round(HillInfo[i].SCALE1, 3).ToString() + ",   " + Math.Round(HillInfo[i].SCALE2, 3).ToString() + ",   " + Math.Round(HillInfo[i].AMAX1, 3).ToString() + ",   " + Math.Round(HillInfo[i].AMAX2, 3).ToString() + "   !";
                    ResultStr += TempStr;
                    ResultStr += "! END !" + "\r\n";
                }



                for (int i = 0; i < this.RecepInfo.Count; i++)
                {
                    c = i + 1;
                    TempStr = c + " !CTREC =      " + Math.Round(RecepInfo[i].XRCT, 5).ToString() + ",   " + Math.Round(RecepInfo[i].YRCT, 5).ToString() + ",   " + Math.Round(RecepInfo[i].ZRCT, 3).ToString() + ",   " + RecepInfo[i].XHH.ToString() + "   !";
                    ResultStr += TempStr;
                    ResultStr += "! END !" + "\r\n";

                }
            }

            return ResultStr;
        }

    }



    public class HillInformation : ICloneable
    {
        private int m_id = 0;//作为记数器
        /// <summary>
        /// 作为记数器
        /// </summary>
        public int Id
        {
            get { return m_id; }
            set { m_id = value; }
        }
        private string m_Sid = "H";//编号用于，唯一标识
        /// <summary>
        /// 编号用于，唯一标识
        /// </summary>
        public string Sid
        {
            get { return m_Sid; }
            set { m_Sid = value; }
        }
        private string m_Name = "";//山体名称,用于界面表现
        /// <summary>
        /// 山体名称用于界面表现
        /// </summary>
        public string Name
        {
            get { return m_Name; }
            set { m_Name = value; }
        }


        /// <summary>
        /// 气象网格的HILL中心的X坐标，单位km
        /// </summary>
        double m_XC;
        /// <summary>
        /// 气象网格的HILL中心的X坐标，单位km
        /// </summary>
        public double XC
        {
            get { return m_XC; }
            set { m_XC = value; }
        }
        /// <summary>
        /// 气象网格的HILL中心的y坐标，单位km
        /// </summary>
        double m_YC;
        /// <summary>
        /// 气象网格的HILL中心的y坐标，单位km
        /// </summary>
        public double YC
        {
            get { return m_YC; }
            set { m_YC = value; }
        }
        /// <summary>
        /// Hill从北开始顺时针方向的主轴方位角
        /// </summary>
        double m_THETAH;
        /// <summary>
        /// Hill从北开始顺时针方向的主轴方位角
        /// </summary>
        public double THETAH
        {
            get { return m_THETAH; }
            set { m_THETAH = value; }
        }
        /// <summary>
        /// 网格 “零平面”在 海平面以上的高度
        /// </summary>
        double m_ZGRID;
        /// <summary>
        /// 网格 “零平面”在 海平面以上的高度
        /// </summary>
        public double ZGRID
        {
            get { return m_ZGRID; }
            set { m_ZGRID = value; }
        }
        /// <summary>
        ///网格高度以上山顶的高度，单位m
        /// </summary>
        double m_RELIEF;
        /// <summary>
        ///网格高度以上山顶的高度，单位m
        /// </summary>
        public double RELIEF
        {
            get { return m_RELIEF; }
            set { m_RELIEF = value; }
        }
        /// <summary>
        /// 山体长轴的形状指数
        /// </summary>
        double m_EXPO1;

        public double EXPO1
        {
            get { return m_EXPO1; }
            set { m_EXPO1 = value; }
        }
        /// <summary>
        /// 山体短轴的形状指数
        /// </summary>
        double m_EXPO2;
        /// <summary>
        /// 山体短轴的形状指数
        /// </summary>
        public double EXPO2
        {
            get { return m_EXPO2; }
            set { m_EXPO2 = value; }
        }
        /// <summary>
        /// 山体长轴方向的水平长度
        /// </summary>
        double m_SCALE1;
        /// <summary>
        /// 山体长轴方向的水平长度
        /// </summary>
        public double SCALE1
        {
            get { return m_SCALE1; }
            set { m_SCALE1 = value; }
        }
        /// <summary>
        /// 山体短轴方向的水平长度
        /// </summary>
        double m_SCALE2;
        /// <summary>
        /// 山体短轴方向的水平长度
        /// </summary>
        public double SCALE2
        {
            get { return m_SCALE2; }
            set { m_SCALE2 = value; }
        }
        /// <summary>
        /// 山体长轴方向的最大允许轴长
        /// </summary>
        double m_AMAX1;
        /// <summary>
        /// 山体长轴方向的最大允许轴长
        /// </summary>
        public double AMAX1
        {
            get { return m_AMAX1; }
            set { m_AMAX1 = value; }
        }
        /// <summary>
        /// 山体短轴方向的最大允许轴长
        /// </summary>
        double m_AMAX2;
        /// <summary>
        /// 山体短轴方向的最大允许轴长
        /// </summary>
        public double AMAX2
        {
            get { return m_AMAX2; }
            set { m_AMAX2 = value; }
        }

        public object Clone()
        {
            return this.MemberwiseClone();
        }
        public HillInformation ReadFromGroup(string str)
        {
            HillInformation h = new HillInformation();

            this.XC = Convert.ToDouble(StrWriter.GetString(str, 1));
            this.YC = Convert.ToDouble(StrWriter.GetString(str, 2));
            this.THETAH = Convert.ToDouble(StrWriter.GetString(str, 3));
            this.ZGRID = Convert.ToDouble(StrWriter.GetString(str, 4));
            this.RELIEF = Convert.ToDouble(StrWriter.GetString(str, 5));
            this.EXPO1 = Convert.ToDouble(StrWriter.GetString(str, 6));
            this.EXPO2 = Convert.ToDouble(StrWriter.GetString(str, 7));
            this.SCALE1 = Convert.ToDouble(StrWriter.GetString(str, 8));
            this.SCALE2 = Convert.ToDouble(StrWriter.GetString(str, 9));
            this.AMAX1 = Convert.ToDouble(StrWriter.GetString(str, 10));
            this.AMAX2 = Convert.ToDouble(StrWriter.GetString(str, 11));
            return h;
        }

    }


    [Serializable]
    public class CTReceptorInfo : ICloneable
    {
        private int m_id = 0; //记数器
        /// <summary>
        /// 记数器
        /// </summary>
        public int Id
        {
            get { return m_id; }
            set { m_id = value; }
        }
        private string m_Sid = "R"; //唯一标识
        /// <summary>
        /// 唯一标识
        /// </summary>
        public string Sid
        {
            get { return m_Sid; }
            set { m_Sid = value; }
        }
        private string m_Name = "接受点"; //名称
        /// <summary>
        /// 名称
        /// </summary>
        public string Name
        {
            get { return m_Name; }
            set { m_Name = value; }
        }


        /// <summary>
        /// CTSG受体的X坐标，单位：km
        /// </summary>
        double m_XRCT = 0;

        public double XRCT
        {
            get { return m_XRCT; }
            set { m_XRCT = value; }
        }
        /// <summary>
        /// CTSG受体的Y坐标，单位：km
        /// </summary>
        double m_YRCT = 0;

        public double YRCT
        {
            get { return m_YRCT; }
            set { m_YRCT = value; }
        }
        /// <summary>
        /// CTSG受体的海拔高度
        /// </summary>
        double m_ZRCT = 0;

        public double ZRCT
        {
            get { return m_ZRCT; }
            set { m_ZRCT = value; }
        }
        /// <summary>
        /// CTSG受体相关的山体数量
        /// </summary>
        int m_XHH = 0;

        public int XHH
        {
            get { return m_XHH; }
            set { m_XHH = value; }
        }
        public object Clone()
        {
            return this.MemberwiseClone();
        }

        public CTReceptorInfo ReadFromGroup(string str)
        {
            CTReceptorInfo c = new CTReceptorInfo();





            this.m_XRCT = Convert.ToDouble(StrWriter.GetString(str, 1));
            this.m_YRCT = Convert.ToDouble(StrWriter.GetString(str, 2));
            this.m_ZRCT = Convert.ToDouble(StrWriter.GetString(str, 3));
            this.m_XHH = Convert.ToInt32(StrWriter.GetString(str, 4));

            return c;
        }

    }




}
